package 笔试.度小满;

import java.util.Scanner;

public class Demo2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int m = sc.nextInt();
        boolean flag = false;
        String[] res = new String[m];
        sc.nextLine();
        for (int i = 0; i < m; i++) {
            String test = sc.nextLine();
            for(int j=0;j<str.length();j++){
                if(str.charAt(j)=='X' && test.charAt(j)=='1'){
                    flag = true;
                    break;
                }
            }
            if(flag){
                res[i]="NO";
            }else{
                res[i]="YES";
            }
            flag = false;
        }
        for (String s:res){
            System.out.println(s);
        }
    }
}
